package com.wis.controller;

import com.wis.entity.NoticeEntity;
import com.wis.service.NoticeService;
import com.wis.util.CommonResult;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;

    @GetMapping(value = "/showAll",produces = MediaType.APPLICATION_JSON_VALUE)
    public CommonResult showNotice(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "7") int limit) {
        return noticeService.showNotice(page, limit);
    }

    // 模糊查询一条Banner
    @GetMapping(value = "/findBlurry",produces = MediaType.APPLICATION_JSON_VALUE)
    public CommonResult findBlurry(@RequestParam(value = "name", defaultValue = "") String name) {
        return noticeService.findBlurry(name);
    }

    //增加一条
    @PostMapping("/add")
    public CommonResult addNotice(@RequestBody NoticeEntity notice) {
        return noticeService.addNotice(notice);
    }

    //删除
    @PostMapping("/del/{id}")
    public CommonResult delNotice(@PathVariable("id") int id) {
        return noticeService.delNotice(id);
    }

    //修改
    @PostMapping("/update")
    public CommonResult updateNotice(@RequestBody NoticeEntity notice) {
        return noticeService.updateNotice(notice);
    }
}

